package com.lnking.lnkingplace.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lnking.common.http.ReturnResult;
import com.lnking.lnkingplace.mapper.StatisticMapper;
import com.lnking.lnkingplace.model.dto.place.PlacePositionDto;
import com.lnking.lnkingplace.model.dto.statistic.*;

import com.lnking.lnkingplace.model.dto.statistic.cultureEnterprise.CultureEnterpriseByYearDto;
import com.lnking.lnkingplace.model.dto.statistic.cultureEnterprise.CultureEnterpriseStatisticsDto;
import com.lnking.lnkingplace.model.dto.statistic.fourEnterprise.FourEnterpriseStatisticsDto;
import com.lnking.lnkingplace.model.request.exhibition.ExhibitionStatisticSearchRequest;
import com.lnking.lnkingplace.model.request.statistic.*;
import com.lnking.lnkingplace.service.IMeetingService;
import com.lnking.lnkingplace.service.IStatisticsService;
import com.lnking.starter.mybatis.entity.IPageInfo;
import com.lnking.starter.mybatis.entity.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.time.LocalDate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 联坤
 */

@RestController
@RequestMapping("/statistic")
@Api(tags = "统计")
public class StatisticsController {

    public static final String MEETING="meeting";
    @Autowired
    IStatisticsService statisticsService;

    @Resource
    StatisticMapper statisticMapper;

    @Autowired
    IMeetingService meetingService;




    @ApiOperation("2.来蓉重点人员排查")
    @GetMapping(value = "/outsiders")
    public ReturnResult outsiders(BaseStatisticParams params){
        Map<String,Integer> data = statisticsService.outsiders(params);
        return ReturnResult.success(data);
    }



    @ApiOperation("3.督查情况")
    @GetMapping(value = "/inspect")
    public ReturnResult inspect(InspectStatisticParams params){
        InspectStatisticDto data = statisticsService.inspectStatistic(params);
        return ReturnResult.success(data);
    }
    @ApiOperation("3.督查信息总表")
    @GetMapping(value = "/inspect/list")
    public ReturnResult inspectList(Page page){
        return ReturnResult.success(statisticsService.inspectList(page));
    }
    @ApiOperation("督查追踪")
    @GetMapping(value = "/inspect/track")
    public ReturnResult inspectTrack(){
        List<PlacePositionDto> data = statisticMapper.inspectTrack();
        return ReturnResult.success(data);
    }

    @ApiOperation("督查追踪一级弹窗")
    @GetMapping(value = "/inspect/track/all/list")
    public ReturnResult inspectTrackAll(){
        return ReturnResult.success(statisticMapper.inspectTrackAll());
    }

    @ApiOperation("督查追踪二级弹窗")
    @GetMapping(value = "/inspect/track/list/info")
    public Object inspectTrackInfo(Page params){
        List list;
        if (params.isPage()) {
            PageHelper.startPage(params.getPageNum(), params.getPageSize());
            list= statisticMapper.inspectTrackInfo();
            PageInfo<Object> page = new PageInfo(list);
            return new IPageInfo(page);
        } else {
            list=statisticMapper.inspectTrackInfo();
            return list;
        }

    }


    @ApiOperation(value = "4.重点行业分布(A级景区)")
    @GetMapping(value = "/important/place/attractions/info")
    public ReturnResult attractions(AttractionsRequest params) {
        AttractionsNumDto dto =statisticsService.attractions(params);
        return ReturnResult.success(dto);
    }

    @ApiOperation(value = "4.重点行业分布(展会场所)")
    @GetMapping(value = "/important/place/exhibition/info")
    public ReturnResult exhibition(ExhibitionRequest params) {
        List<ExhibitionDto> dto=null;
        if (null == params.getStartDate()&&params.getEndDate() == null) {
            params.setStartDate(LocalDate.now());
             dto =statisticsService.exhibition(params);
             if (dto.size() == 0){
                 dto = statisticsService.exhibitionLast();
             }
        }else {
              dto =statisticsService.exhibition(params);
        }
        return ReturnResult.success(dto);
    }

    @ApiOperation("5.重点企业数量(文创)")
    @GetMapping(value = "/important/company/info")
    public ReturnResult cultureEnterpriseTypeNum(){
        Map<String, Object> result = new HashMap<>();
        result.put("cultureInfo", statisticsService.cultureEnterpriseStatistics());
        result.put("fourInfo", statisticsService.fourEnterpriseStatistics());
        return ReturnResult.success(result);
    }

    @ApiOperation("5.重点企业弹窗")
    @GetMapping(value = "/important/company/list")
    public ReturnResult importantCompanyList(ExhibitionPlaceListRequest params){

        return ReturnResult.success(statisticsService.importantCompanyList(params));
    }

    @ApiOperation(value = "人员行业分布")
    @GetMapping(value = "/user-distribution")
    public ReturnResult userPlace(UserPlaceRequest params) {
        UserPlaceDto dto =statisticsService.userPlace(params);
        return ReturnResult.success(dto);
    }

    @ApiOperation(value = "行业人数列表(疫情)")
    @GetMapping(value = "/place/type/check/today/list")
    public ReturnResult placeTypeCheckTodayList(UserPlaceRequest params) {
        List<PlaceTypeCheckListDto> dto =statisticsService.placeTypeCheckList(params);
        return ReturnResult.success(dto);
    }

    @ApiOperation(value = "行业人数列表(常态化)")
    @GetMapping(value = "/place/type/check/list")
    public ReturnResult placeTypeCheckList(UserPlaceRequest params) {
        return ReturnResult.success(statisticsService.personPlaceData(params));
    }


    @ApiOperation(value = "行业二级弹窗")
    @GetMapping(value = "/place/street/type/list")
    public ReturnResult placeStreetTypeList(Page params) {
        return ReturnResult.success(statisticsService.placeStreetTypeList(params));
    }



    @ApiOperation("会展场所信息统计")
    @GetMapping(value = "/exhibition")
    public ReturnResult getExhibitionStatisticInfo(ExhibitionStatisticSearchRequest params){
        return ReturnResult.success(statisticsService.getExhibitionStatisticInfo(params));
    }

    @ApiOperation("会展企业列表")
    @GetMapping(value = "/exhibition/place/list")
    public ReturnResult getExhibitionPlaceList(ExhibitionPlaceListRequest params){
        return ReturnResult.success(statisticsService.getExhibitionPlaceList(params));
    }



    @ApiOperation("获取核酸当日检测率")
    @PostMapping("/today-check-number")
    public ReturnResult getTodayCheckRate(@RequestBody PersonCheckStatusSearchParams params) {
        return ReturnResult.success(statisticsService.getTodayCheckRate(params));
    }

//    @ApiOperation(value = "督察抽查统计")
//    @GetMapping(value = "/inspect")
//    public ReturnResult inspect() {
//        InspectDto dto =statisticsService.inspect();
//        return ReturnResult.success(dto);
//    }

    @ApiOperation(value = "综合数据展示")
    @GetMapping(value = "/comprehensive")
    public ReturnResult integrated() {
        IntegratedDto dto =statisticsService.integrated();
        return ReturnResult.success(dto);
    }

    @ApiOperation(value = "隔离人员数据")
    @GetMapping(value = "/isolation")
    public ReturnResult isolation() {
        IsolationDto dto =statisticsService.isolation();
        return ReturnResult.success(dto);
    }

    @ApiOperation(value = "隔离观察房间情况")
    @GetMapping(value = "/isolation-room")
    public ReturnResult room() {
        CommonIsolationDto dto =statisticsService.isolationRoom();
        return ReturnResult.success(dto);
    }

    @ApiOperation(value = "隔离观察人员情况")
    @GetMapping(value = "/isolation-user")
    public ReturnResult isolationUser() {
        CommonIsolationDto dto =statisticsService.isolationUser();
        return ReturnResult.success(dto);
    }

    @ApiOperation(value = "驻点团队人员情况")
    @GetMapping(value = "/isolation-worker")
    public ReturnResult isolationWorker() {
        CommonIsolationDto dto =statisticsService.isolationWorker();
        return ReturnResult.success(dto);
    }

    @ApiOperation("导出excel")
    @GetMapping(value = "/export")
    public ReturnResult exportExcel(StatisticExportParams params, HttpServletResponse response) throws Exception{
        statisticsService.exportExcel(params, response);
        return ReturnResult.success();
    }




}
